<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>数据内容管理</title>
<script type="text/javascript">
	var $grid;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/basic/dataDetail/dataGrid",
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'dataNo',
				title : '数据内容编号',
				width : 140,
				sortable : true
			}, {
				field : 'dataName',
				title : '数据内容名称',
				width : 160,
				sortable : true
			}, {
				field : 'dataType',
				title : '数据内容类型',
				width : 160,
				sortable : true,
				formatter : function(value, row, index) {
					row['dataType'] = value.id;//设置数据类型ID
					return value ? value.codeName : "";
				}
			}, {
				field : 'remark',
				title : '备注',
				width : 240,
				sortable : true
			}, {
				field : 'enable',
				title : '是否启用',
				width : 140,
				formatter : function(value, row, index) {
					return '<input class="easyui-switchbutton "' + (value == 1 ? "checked" : "") 
					+ ' data-options="readonly:true,onText:\'是\',offText:\'否\'">';
				}
			} ] ]
		}));
		$grid.datagrid('enableFilter', [ buildDGFilterYesOrNoFieldOptions($grid, 'enable'), {
			field : 'dataType',
			searchField : 'dataType.codeName'
		} ]);
		
		$("#enableSB").switchbutton({
			onText:"是",
			offText:"否",
			checked:true,
			onChange:function(checked){
				if(checked){
					$("#enable").val(1);
				}else{
					$("#enable").val(2);
				}
			}
		});
		
		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load', {
				enable : 1
			});
			$("#enableSB").switchbutton("check");
			//$("#radio1").click();
			$("#dlg").dialog("open").dialog("setTitle", "新增数据内容");
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法编辑",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$("#dlg").dialog("open").dialog("setTitle", "编辑数据内容");
				$("#fm").form("load", rowData);
				$("#enableSB").switchbutton(rowData.isOverride == 1?"check":"uncheck");
				
			}
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/basic/dataDetail/multiDelete");
		});
		$("#search").click(function() {
			var obj = {};
			$("#tt").find("input").each(function() {
				var key = $(this).attr("name");
				obj[key] = $(this).val();
			});
			$grid.datagrid('load', obj);
		});
		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "DataDetail",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
		$("#excelExport").click(function() {
			var url = "${ctx}/basic/dataDetail/excelExport?" + $.param($grid.datagrid('options').queryParams);
			if ($grid.datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($grid.datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});

		fn_initCombo("dataType", "dataType", true);//数据内容类型
	});
	function fn_save() {
		$("#fm").form("submit", {
			url : "${ctx}/basic/dataDetail/update",
			success : function(data) {
				$grid.datagrid("load");
				$.messager.show({
					msg : "保存成功",
					icon : "info",
					position : "bottomRight"
				});
				$("#dlg").dialog('close');
			}
		});
	}
</script>
</head>

<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
	<div class="col-md-6">
		<shiro:hasPermission name="dataDetail:list">
		<form class="form-grid-search form-inline">
				<div class="form-group">
					<input type="text" class="form-control" name="search_LIKE_dataName" placeholder="内容名称" />
					<input type="text" class="form-control" name="search_LIKE_codeValues.codeName" placeholder="内容类型" />
				</div>
				<button type="button" id="search" class="btn btn-primary">
					<span class="glyphicon glyphicon-search"></span> 查询
				</button>
			</form>
		</shiro:hasPermission>
		</div>
		<div class="col-md-6">
		<shiro:hasPermission name="dataDetail:update">
			<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="dataDetail:delete">
			<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="dataDetail:import">
			<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导入
				</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="dataDetail:export">
			<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导出
				</button>
		</shiro:hasPermission>
		</div>
	</div>
	<shiro:hasPermission name="dataDetail:list">
		<div id="dlg" class="easyui-dialog" style="width: 370px; height: 350px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" />
				<table id="tbl">
					<tr>
						<td><label>数据内容编号:</label></td>
						<td><input name="dataNo" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<td><label>数据内容名称:</label></td>
						<td><input name="dataName" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<td><label>数据内容类型:</label></td>
						<td><input id="dataType" name="dataType" /></td>
					</tr>
					<tr>
						<td><label>是否启用:</label></td>
						<td><input type="hidden" id="enable" name="enable" ><input id="enableSB"></td>
					</tr>
					<tr>
						<td><label>备注:</label></td>
						<td><input name="remark" class="easyui-textbox" data-options="multiline:true,width:185,height:60"></td>
					</tr>
				</table>
			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="fn_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>
	</shiro:hasPermission>
</body>
</html>
